package com.numbfish.ch01_ex03_bean_processor;

import com.numbfish.ch01_ex03_bean_processor.config.CustomConfig;
import com.numbfish.ch01_ex03_bean_processor.pojo.Person;
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Arrays;

//@SpringBootTest
@Slf4j

public class Ch01Ex03BeanProcessorTestApp {
    //@Autowired
    private  ApplicationContext applicationContext;

    private AnnotationConfigApplicationContext annotationConfigapplicationContext=new AnnotationConfigApplicationContext(CustomConfig.class);


    @Test
    void contextLoads() {
        log.info("applicationContext = {}",applicationContext);
    }
    @Test
    void beanCount(){
        // 用户未定义任何类时的bean个数为 springBoot2.7 : 139
        // 用户未定义任何类时的bean个数为 springBoot3   : 152
        log.info("applicationContext default bean count= {}",applicationContext.getBeanDefinitionNames().length);
    }


    void outputTheBeanFromContext(Class<?> clazz){
        // 用户未定义任何类时的bean个数为152
        log.info("applicationContext get a bean  {} === {}",clazz,applicationContext.getBean(clazz));
    }
    @Test
    void getBeanCount(){
        int count = annotationConfigapplicationContext.getBeanDefinitionCount();
        System.out.println("annotationConfigapplicationContext count====="+count);
    }
    @Test
    void getBeanPerson(){
        Person person = annotationConfigapplicationContext.getBean(Person.class);
        System.out.println(person);
    }




}